package com.rong.shop.controller;

import com.rong.shop.pojo.Order;
import com.rong.shop.service.IOrderService;
import com.rong.shop.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/order")
public class OrderController extends BaseController{

    @Autowired
    private IOrderService orderService;

//  http://localhost:8080/order/create?aid=22&uid=8&cids=5&cids=6&cids=7
    @RequestMapping("/create")
    @ResponseBody
    public JsonResult<Order> create(HttpSession session, Integer aid, Integer[] cids){
        Integer uid = getUidFromSession(session);
        String username = getUsernameFromSession(session);
        Order order = orderService.create(aid, uid, username, cids);
        return new JsonResult<Order>(OK, order);
    }


}
